package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.gmc.global.api.common.dto.TenantUserDTO;
import com.ibeeking.gmc.global.api.common.param.PermissionParam;
import com.ibeeking.gmc.global.api.feign.UpmsTenantUserClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class UpmsUserFallbackFactory implements FallbackFactory<UpmsTenantUserClient> {
    @Override
    public UpmsTenantUserClient create(Throwable throwable) {
        return new UpmsTenantUserClient() {
            @Override
            public ResponseResult<TenantUserDTO> queryByMobile(String mobile) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询租户用户信息失败。");
            }

            @Override
            public ResponseResult<List<TenantUserDTO>> queryByTenantId(Integer tenantId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询租户用户信息失败。");
            }

            @Override
            public ResponseResult<List<Long>> menus(@NotBlank(message = "模块不能为空") String module) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询模块菜单失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<Boolean> configurePermission(List<PermissionParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，配置模块菜单失败。", false);
            }

            @Override
            public ResponseResult<TenantUserDTO> queryShopUserByMobile(String mobile) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询商户员工失败。", null);
            }
        };
    }
}
